using System;
using System.Configuration;
using Reimers.Map;

public partial class examples_csharp_eventhandler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Set the map to load the Google key from the web.config
        GMap.GoogleKey = ConfigurationManager.AppSettings["MapKey"];
        if (!Page.IsPostBack) GMap.Center = new Reimers.Map.GoogleLatLng(54, 0);
        //Programatically attach event handler
        GMap.MoveEnd += new MoveEndHandler(GMap_MoveEnd);
    }

    void GMap_MoveEnd(object sender, BoundsEventArgs e)
    {
        string msg = string.Format("<p>Map bounds are:</p><p>North Lat: {0},<br/>South Lat: {1},<br />East Lng: {2},<br />West Lng: {3}",
            e.Bounds.MaxLatitude.ToString(),
            e.Bounds.MinLatitude.ToString(),
            e.Bounds.MaxLongitude.ToString(),
            e.Bounds.MinLongitude.ToString()
        );
        e.MapCommand = e.Map.OpenInfoWindowHTML(e.Bounds.Center, msg, new GoogleInfoWindowOptions(true));
    }

    //This handler is added using the reference in the markup and the autoEventWireup parameter in the page directive.
    protected void MapClick(object sender, CoordinatesEventArgs e)
    {
        e.MapCommand = e.Map.OpenInfoWindowHTML(e.Coordinates, string.Format("Lat: {0}<br />Lng: {1}", e.Coordinates.Latitude.ToString(), e.Coordinates.Longitude.ToString()));
    }
}
